package com.lyz.dataStructure.algorithm.qushikeji2020;


import java.util.Scanner;

/*

 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] arr = new int[6];
       for(int i=0;i<6;i++){
           arr[i] = sc.nextInt();
       }
        int n = sc.nextInt();
        System.out.println(coin(arr,n));
    }

    public  static  int coin(int[] coins,int n){
        if(n==0){
            return 0;
        }
        int[] dp = new int[n+1];
        for(int i =1;i<n;i++){
            dp[i] = 999999;
            for(int coin:coins){
                if(i-coin>=0){
                    dp[i] = Math.min(dp[i-coin]+1,dp[i]);
                }
            }
        }
        return dp[n] == 999999?-1:dp[n];
    }
}
